home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Dev / misc / StripHunk.lha / StripHunk / StripHunk.s < prev    next >
Encoding:
Text File  |  2003-12-26  |  52.8 KB  |  1,780 lines

  1. *****************************************************************************
  2. *                                        *
  3. *    PROGRAM: StripHunk                            *
  4. *    VERSION: 1.3                                *
  5. *   SOURCE CODE: 28 (7.11.2000)                            *
  6. *       DATE: 23.09.1997 - 05.10.1999                    *
  7. *      LANGUAGE: Assembler (DevPac V3.14)                    *
  8. *     SYSTEM: A1200    KS 40.68 WB 40.42 2MB chip 8MB fast 68030/50mhz        *
  9. *                                        *
  10. *     AUTHOR: Joerg Riemer 14167 Berlin/SchottmuellerStr.107/Germany        *
  11. *      EMAIL: joerg_riemer@freenet.de / mission@cs.tu-berlin.de        *
  12. *                                        *
  13. *      FUNCTION: changes hunk_reloc32 <-> hunk_drel32                *
  14. *         removes debug_hunks like $3E8,$3F0,$3F1            *
  15. *         sorts reloc_entrys from low to high and reverse        *
  16. *                                        *
  17. *****************************************************************************
  18.  
  19. BSS_Section    set    0
  20.  
  21. *****************************************************************************
  22.  
  23.         OUTPUT    RAM:StripHunk
  24.  
  25. *****************************************************************************
  26.  
  27. ASLFR_DoMultiSelect    equ    $8008002D
  28. ASLFR_DoPatterns    equ    $8008002E
  29. ASLFR_DoSaveMode    equ    $8008002C
  30. ASLFR_DrawersOnly    equ    $8008002F
  31. ASLFR_InitialFile    equ    $80080008
  32. ASLFR_TitleText        equ    $80080001
  33.  
  34. fr_Drawer        equ    $008
  35. fr_File            equ    $004
  36. fr_ArgList        equ    $024
  37. fr_NumArgs        equ    $020
  38.  
  39. _LVOAllocAslRequest    equ    -048
  40. _LVOFreeAslRequest    equ    -054
  41. _LVOAslRequest        equ    -060
  42.  
  43. *****************************************************************************
  44.  
  45. HUNK_HEADER        equ    1011
  46.  
  47. MODE_OLDFILE             equ    1005
  48. MODE_NEWFILE             equ    1006
  49.  
  50. ACCESS_READ        equ    -002
  51.  
  52. fib_Protection        equ    $074
  53. fib_Size        equ    $07C
  54. fib_Comment        equ    $090
  55. fib_SIZEOF        equ    $104
  56.  
  57. FIBB_ARCHIVE        equ    $004
  58.  
  59. _LVOOpen                  equ    -030
  60. _LVOClose                  equ    -036
  61. _LVORead                   equ    -042
  62. _LVOWrite                  equ    -048
  63. _LVOOutput                 equ    -060
  64. _LVODeleteFile             equ    -072
  65. _LVORename                equ    -078
  66. _LVOLock                  equ    -084
  67. _LVOUnLock                 equ    -090
  68. _LVOCurrentDir             equ    -126
  69. _LVOIoErr                  equ    -132
  70. _LVOSetComment             equ    -180
  71. _LVOSetProtection         equ    -186
  72. _LVOFlush                  equ    -360
  73. _LVOExamineFH              equ    -390
  74. _LVOSetIoErr               equ    -462
  75. _LVOPrintFault             equ    -474
  76. _LVOCheckSignal            equ    -792
  77. _LVOReadArgs               equ    -798
  78. _LVOFreeArgs               equ    -858
  79. _LVOFilePart               equ    -870
  80. _LVOPutStr                 equ    -948
  81. _LVOVPrintf                equ    -954
  82.  
  83. *****************************************************************************
  84.  
  85. _LVOAllocMem              equ    -198
  86. _LVOFreeMem                equ    -210
  87. _LVOCloseLibrary           equ    -414
  88. _LVOOpenLibrary            equ    -552
  89. _LVOCacheClearU            equ    -636
  90.  
  91. *****************************************************************************
  92.  
  93. DataBase1    rs.b    0
  94.  
  95. DOSBase        rs.l    1
  96. ASLBase        rs.l    1
  97.  
  98. *****************************************************************************
  99.  
  100. ArgArray    rs.b    0
  101.  
  102. LFile        rs.l    1
  103. SFile        rs.l    1
  104. Replace        rs.l    1
  105. DRel32        rs.l    1
  106. Split        rs.l    1
  107. Reloc32        rs.l    1
  108. Sort        rs.l    1
  109. Reverse        rs.l    1            ;sort reverse (7.11.00)
  110. Symbol        rs.l    1
  111. Debug        rs.l    1
  112. Name        rs.l    1
  113. Zeros        rs.l    1
  114. AslReq        rs.l    1
  115. Quiet        rs.l    1
  116.  
  117. RArgPtr        rs.l    1
  118.  
  119. *****************************************************************************
  120.  
  121. FileCnt        rs.l    1            ;counter (files to operate)
  122.  
  123. *****************************************************************************
  124.  
  125. ASLFlag         rs.l    1            ;flag (using ASL)
  126.  
  127. LREQBase     rs.l    1
  128. SREQBase     rs.l    1
  129.  
  130. *****************************************************************************
  131.  
  132. RCode        rs.l    1            ;buffer for returncode
  133. IOErr        rs.l    1            ;buffer for io_error
  134.  
  135. *****************************************************************************
  136.  
  137. DataBase2    rs.b    0            ;cleared for every file
  138.  
  139. LName        rs.b    32            ;buffer filename (load)
  140. SName        rs.b    32            ;buffer filename (save)
  141. BName        rs.b    32            ;buffer backupname
  142.  
  143. LPath        rs.l    1            ;strptr path (load)
  144. LPLock        rs.l    1            ;lock currentdir (load)
  145. OldLDir        rs.l    1            ;lock prev. dir
  146. FHandleL    rs.l    1            ;filehandle (old file)
  147.  
  148. SPath        rs.l    1            ;strptr path (save)
  149. SPLock        rs.l    1            ;lock currentdir (save)
  150. OldSDir        rs.l    1            ;lock prev. dir
  151. FHandleS    rs.l    1            ;filehandle (new file)
  152.  
  153. OvlHunk        rs.l    1            ;pointer overlay_hunk
  154.  
  155. RdSize        rs.l    1            ;reduced size (over all)
  156.  
  157. NFSize        rs.l    1            ;new filesize
  158. Memory        rs.l    1            ;mem-ptr (current file)
  159.  
  160. EFlag1        rs.b    1            ;overlay found
  161. EFlag2        rs.b    1            ;(name/symbol/debug) removed
  162. EFlag3        rs.b    1            ;reloc changed (strip/revert)
  163. EFlag4        rs.b    1            ;save error
  164.  
  165. EFlag5        rs.b    1            ;empty hunk found
  166. EFlag6        rs.b    1            ;dummy for longword align
  167. EFlag7        rs.b    1            ;dummy for longword align
  168. EFlag8        rs.b    1            ;dummy for longword align
  169.  
  170. ProgID        rs.l    2            ;buffer for hunk_header_id
  171.  
  172. Buffer        rs.l    1
  173.  
  174. ***********************************************  file info block ************
  175.  
  176. FIBlock        rs.b    fib_SIZEOF        ;buffer for fileinfoblock
  177.  
  178. BSS_Size1    rs.b    0            ;bss_size over all
  179.  
  180. BSS_Size2    set    BSS_Size1-DataBase2    ;required for inner circle
  181.  
  182. *****************************************************************************
  183.  
  184.         if    BSS_Section
  185.  
  186. ProgStart    movea.l    ProgStart-4(pc),A5    ;get bss_section
  187.         addq.l    #1,A5            ;skip pointer (next segment)
  188.         adda.l    A5,A5            ;convert bpcl_pointer
  189.         adda.l    A5,A5            ;to real_address
  190.  
  191.         elseif
  192.  
  193. ProgStart    lea    DataBase(pc),A5        ;get database
  194.  
  195.         endc
  196.  
  197. *****************************************************************************
  198.  
  199.         movea.l    4.w,A6            ;set EXEC to call a function
  200.  
  201.         moveq    #20,D0            ;get failat level
  202.         move.l    D0,RCode(A5)        ;preset returncode (no dos)
  203.  
  204.         moveq    #37,D0            ;set required version
  205.         lea    DOSName(pc),A1        ;get libraryname
  206.         jsr    _LVOOpenLibrary(A6)    ;use EXEC to (openlibrary)
  207.         move.l    D0,DOSBase(A5)        ;save returned pointer
  208.  
  209.         beq.b    CloseLibs        ;branch on fail
  210.  
  211.         moveq    #0,D0            ;set required version
  212.         lea    ASLName(pc),A1        ;get libraryname
  213.         jsr    _LVOOpenLibrary(A6)    ;use EXEC to (openlibrary)
  214.         move.l    D0,ASLBase(A5)        ;save returned pointer
  215.  
  216. *****************************************************************************
  217.  
  218.         bsr.b    Main0
  219.  
  220. *****************************************************************************
  221.  
  222. CloseLibs    movea.l    4.w,A6            ;set EXEC to call a function
  223.  
  224.         move.l    ASLBase(A5),D1        ;get base_ptr
  225.         beq.b    CloseDOS        ;branch when not open
  226.         movea.l    D1,A1            ;set base_ptr
  227.         jsr    _LVOCloseLibrary(A6)    ;use EXEC to (closelibrary)
  228.  
  229. CloseDOS    move.l    DOSBase(A5),D1        ;get base_ptr
  230.         beq.b    QuitClose        ;branch when not open
  231.         movea.l    D1,A1            ;set base_ptr
  232.         jsr    _LVOCloseLibrary(A6)    ;use EXEC to (closelibrary)
  233.  
  234. QuitClose    move.l    RCode(A5),D0        ;set returncode
  235.         rts                ;back to shell
  236.  
  237. *****************************************************************************
  238.  
  239. DOSName        dc.b    "dos.library",0
  240. ASLName        dc.b    "asl.library",0
  241.  
  242. *****************************************************************************
  243.  
  244. version dc.b "$VER: striphunk 1.3 28 (7.11.00) by joerg riemer sep'97",0,0
  245.  
  246. *****************************************************************************
  247.  
  248. Main0        bsr    ReadArgs        ;read arguments by dos
  249.         bsr    CheckArgs        ;check for wrong arguments
  250.         bsr    OpenREQs        ;open filerequester
  251.  
  252. Main1        moveq    #0,D0            ;get failat level
  253.         move.l    D0,RCode(A5)        ;set returncode
  254.  
  255. Main2        movea.l    DOSBase(A5),A6        ;set DOS to call a function
  256.  
  257.         bsr    ChkBreak        ;check for break by (ctrl_c)
  258.         bsr    PrepLSrc        ;prepare fname/fdir. (src.)
  259.         bsr    PrintT00        ;print "processing FILE:"
  260.         bsr    LoadFile        ;load file
  261.         bsr    PrepFile        ;parse file, strip hunks
  262.         bsr    ChkBreak        ;check for break by (ctrl_c)
  263.         bsr    PrepSDst        ;prepare fname/fdir. (dst.)
  264.         bsr    PrintTBS        ;print "bytes saved"
  265.         bsr    PrintT02        ;print "writing"
  266.         bsr    SaveFile        ;save file to disk
  267.         bsr    PrintT04        ;print "done."
  268.  
  269. Main3        bsr.b    FreeMem            ;free file_mem
  270.         bsr.b    ResetData        ;clear used datas
  271.  
  272.         moveq    #1,D0            ;decrement
  273.         sub.l    D0,FileCnt(A5)        ;file counter
  274.         bpl.b    Main2            ;loop until -1
  275.  
  276. Main4        bsr.b    CloseREQ        ;free both asl requester
  277.         bsr.b    FreeArgs        ;unset readargs
  278.         bsr.b    SetIOErr        ;try to set last io_error
  279.         rts                ;go back to shell
  280.  
  281. ***********************************************  clear database *************
  282.  
  283. ResetData    lea    DataBase2(A5),A0    ;get base of datas
  284.         move.w    #BSS_Size2-1,D0        ;set size to clear
  285.         moveq    #0,D1            ;prepare clear register
  286. ClearMemory    move.b    D1,(A0)+        ;clear datas
  287.         dbra    D0,ClearMemory        ;until overflow
  288.         rts                ;go back
  289.  
  290. ***********************************************  free file memory ***********
  291.  
  292. FreeMem        move.l    Memory(A5),D1        ;get file memory
  293.         beq.b    QuitFreeM        ;branch if not set
  294.         movea.l    D1,A1            ;set memory base
  295.         lea    FIBlock(A5),A0        ;get fileinfoblock
  296.         move.l    fib_Size(A0),D0        ;set filesize
  297.         add.l    D0,D0            ;add working area
  298.         movea.l    4.w,A6            ;set EXEC to call a function
  299.         jsr    _LVOFreeMem(A6)        ;use EXEC to (freemem)
  300. QuitFreeM    rts                ;go back
  301.  
  302. *****************************************************************************
  303.  
  304. CloseREQ    movea.l    ASLBase(A5),A6        ;set ASL to call a function
  305.  
  306.         move.l    LREQBase(A5),D0        ;test requester base
  307.         beq.b    CloseFREQ        ;branch if not open
  308.         movea.l    D0,A0            ;set requester base
  309.         jsr    _LVOFreeAslRequest(A6)    ;use ASL to (freeaslrequest)
  310.  
  311. CloseFREQ    move.l    SREQBase(A5),D0        ;test requester base
  312.         beq.b    QuitCREQ        ;branch if not open
  313.         movea.l    D0,A0            ;set requester base
  314.         jsr    _LVOFreeAslRequest(A6)    ;use ASL to (freeaslrequest)
  315.  
  316. QuitCREQ    rts                ;go back
  317.  
  318. ***********************************************  free arguments *************
  319.  
  320. FreeArgs    lea    ArgArray(A5),A1        ;get argarray
  321.         move.l    RArgPtr(A5),D1        ;set readarg pointer
  322.         movea.l    DOSBase(A5),A6        ;set DOS to call a function
  323.         jsr    _LVOFreeArgs(A6)    ;use DOS to (freeargs)
  324.         rts                ;go back
  325.  
  326. ***********************************************  set last io_error **********
  327.  
  328. SetIOErr    move.l    IOErr(A5),D1        ;set last io_error
  329.         beq.b    QuitIOErr        ;branch if there is nothing
  330.         movea.l    DOSBase(A5),A6        ;set DOS to call a function
  331.         jsr    _LVOSetIoErr(A6)    ;use DOS to (setioerr)
  332. QuitIOErr    rts                ;go back
  333.  
  334. ***********************************************  strip/revert hunks/relocs **
  335.  
  336. PrepFile    movea.l    Memory(A5),A0        ;get base of current file
  337.         movea.l    A0,A1            ;prepare end of file
  338.         lea    FIBlock(A5),A2        ;get fileinfoblock
  339.         adda.l    fib_Size(A2),A1        ;add filesize
  340.  
  341. Loop        cmpa.l    A0,A1            ;check for eof
  342.         bne.b    ParseHunk        ;branch if so
  343.  
  344.         move.l    A1,D0            ;set end of file
  345.         sub.l    Memory(A5),D0        ;calculate new filesize
  346.         move.l    D0,NFSize(A5)        ;and save
  347.  
  348.         move.b    EFlag2(A5),D0        ;removed some hunks ?
  349.         or.b    EFlag3(A5),D0        ;stripped some relocs ?
  350.         bne.b    QuitParse        ;branch if so
  351.  
  352.         bsr    PrintT06        ;print "untouched"
  353.  
  354.         addq.l    #4,SP            ;skip some sub-routines
  355.         pea    Main3(pc)        ;do the next file
  356.  
  357. QuitParse    rts                ;go back
  358.  
  359. ************************************************
  360.  
  361. ParseHunk    move.l    (A0),D0            ;get hunk_id from file
  362.         moveq    #23,D1            ;set loop counter
  363.         lea    HunkTable(pc),A2    ;set id_table
  364. SearchID    move.w    D1,D2            ;prepare offset
  365.         add.w    D2,D2            ;want it in words
  366.         cmp.w    (A2,D2.W),D0        ;found hunk_id ?
  367.         dbeq    D1,SearchID        ;dbranch if not
  368.  
  369.         bne    PrintError1        ;branch when nothing found
  370.  
  371.         move.w    JmpTable(pc,D2),D2    ;calculate jump_address
  372.         jmp    JmpTable(pc,D2)        ;parse current hunk
  373.  
  374. *** available hunks *********************************************************
  375. *                                        *
  376. *   00)*hunk_unit      -( 999/$3E7) 01)+hunk_name         #(1000/$3E8)   *
  377. *   02)+hunk_code      #(1001/$3E9) 03)+hunk_data         #(1002/$3EA)   *
  378. *   04)+hunk_bss      #(1003/$3EB) 05)+hunk_reloc         #(1004/$3EC)   *
  379. *   06)*hunk_reloc16      -(1005/$3ED) 07)*hunk_reloc8         -(1006/$3EE)   *
  380. *   08)*hunk_ext      -(1007/$3EF) 09)+hunk_symbol         #(1008/$3F0)   *
  381. *   10)+hunk_debug      #(1009/$3F1) 11)+hunk_end         #(1010($3F2)   *
  382. *   12)+hunk_header      #(1011/$3F3) 13)*              (1012/$3F4)   *
  383. *   14)+hunk_overlay      #(1013/$3F5) 15)+hunk_break         #(1014/$3F6)   *
  384. *   16)+hunk_drel32      #(1015/$3F7) 17)*hunk_drel16         ?(1016/$3F8)   *
  385. *   18)*hunk_drel8      ?(1017/$3F9) 19)*hunk_lib         ?(1018/$3FA)   *
  386. *   20)*hunk_index      ?(1019/$3FB) 21)+hunk_reloc32short #(1020/$3FC)   *
  387. *   22)*hunk_relreloc32      ?(1021/$3FD) 23)*hunk_absreloc16   ?(1022/$3FE)   *
  388. *                                        *
  389. *****************************************************************************
  390.  
  391. HunkTable    dc.w    $3E7,$3E8,$3E9,$3EA,$3EB,$3EC,$3ED,$3EE
  392.         dc.w    $3EF,$3F0,$3F1,$3F2,$3F3,$3F4,$3F5,$3F6
  393.         dc.w    $3F7,$3F8,$3F9,$3FA,$3FB,$3FC,$3FD,$3FE
  394.  
  395. JmpTable    dc.w    PrintError1-JmpTable,ParseHunk01-JmpTable
  396.         dc.w    ParseHunk02-JmpTable,ParseHunk03-JmpTable
  397.         dc.w    ParseHunk04-JmpTable,ParseHunk05-JmpTable
  398.         dc.w    PrintError1-JmpTable,PrintError1-JmpTable
  399.         dc.w    PrintError1-JmpTable,ParseHunk09-JmpTable
  400.         dc.w    ParseHunk10-JmpTable,ParseHunk11-JmpTable
  401.         dc.w    ParseHunk12-JmpTable,PrintError1-JmpTable
  402.         dc.w    ParseHunk14-JmpTable,ParseHunk15-JmpTable
  403.         dc.w    ParseHunk16-JmpTable,PrintError1-JmpTable
  404.         dc.w    PrintError1-JmpTable,PrintError1-JmpTable
  405.         dc.w    PrintError1-JmpTable,ParseHunk21-JmpTable
  406.         dc.w    PrintError1-JmpTable,PrintError1-JmpTable
  407.  
  408. * hunk_name #(1000/$3E8) ****************************************************
  409.  
  410. ParseHunk01    tst.b    Name(A5)        ;delete hunk_name ?
  411.         beq.b    ParseHunk02        ;branch if not
  412.  
  413. ************************
  414.  
  415. DeleteHunk    st    EFlag2(A5)        ;set flag (hunk removed)
  416.  
  417.         movea.l    A0,A2            ;prepare work_register
  418.         addq.l    #4,A2            ;skip hunk_id
  419.         move.l    (A2),D0            ;set hunk_length
  420.         lsl.l    #2,D0            ;want it in bytes
  421.         lea    4(A2,D0.l),A2        ;get hunk_end
  422.  
  423. ************************
  424.  
  425. ShrinkFile    st    EFlag3(A5)        ;set flag (file changed)
  426.  
  427.         move.l    A0,D0            ;calculate size
  428.         sub.l    A2,D0            ;to shrink
  429.         add.l    D0,RdSize(A5)        ;add (reduced)size [over all]
  430.  
  431. .Shrink        move.l    (A2),(A2,D0.l)        ;shrink file
  432.         addq.l    #4,A2            ;long by long
  433.         cmpa.l    A2,A1            ;until eof
  434.         bne.b    .Shrink
  435.  
  436.         adda.l    D0,A1            ;file is now bit smaller
  437.         bra    Loop            ;go back (parse next hunk)
  438.  
  439. * hunk_debug #(1009/$3F1) *********************
  440.  
  441. ParseHunk10    tst.b    Debug(A5)        ;want to remove hunk_debug ?
  442.         bne.b    DeleteHunk        ;branch if so
  443.  
  444. * hunk_data #(1002/$3EA) **********************
  445.  
  446. ParseHunk03                    ;same like hunk_code
  447.  
  448. * hunk_code #(1001/$3E9) **********************
  449.  
  450. ParseHunk02    addq.l    #4,A0            ;skip hunk_id
  451.  
  452.         movea.l    A0,A2            ;hunk_length, required later
  453.  
  454.         move.l    (A0),D0            ;get longs to skip
  455.         sne    EFlag5(A5)        ;set flag if hunk empty
  456.         lsl.l    #2,D0            ;want it in bytes
  457.         lea    4(A0,D0.l),A0        ;jump to hunk_end
  458.  
  459.         tst.b    EFlag5(A5)        ;check for empty hunk
  460.         beq    Loop            ;branch if so
  461.  
  462.         tst.b    Zeros(A5)        ;remove zeros ?
  463.         beq    Loop            ;branch if not
  464.  
  465.         movea.l    A0,A3            ;prepare work_register
  466. .ChkZeros    tst.l    -(A0)            ;calc length
  467.         beq.b    .ChkZeros        ;of zeros (backward)
  468.         addq.l    #4,A0            ;reset address
  469.         cmpa.l    A0,A3            ;found some zeros ?
  470.         beq    Loop            ;branch if not
  471.  
  472.         st    EFlag2(A5)        ;set flag, backup only
  473.  
  474.         move.l    A3,D0            ;recalculate
  475.         sub.l    A0,D0            ;hunk_length
  476.         lsr.l    #2,D0            ;requires longs
  477.         sub.l    D0,(A2)            ;reset hunk_length
  478.  
  479.         movea.l    A3,A2            ;prepare work_register
  480.         bra.b    ShrinkFile        ;and shrink file
  481.  
  482. * hunk_symbol #(1008/$3F0) ********************
  483.  
  484. ParseHunk09    movea.l    A0,A2            ;save hunkbase
  485.  
  486.         addq.l    #4,A0            ;skip hunk_id
  487.         move.l    (A0)+,D0        ;get longs to skip
  488.         beq.b    .RemoveSymbol        ;branch if end_mark
  489.  
  490. .SkipSymbol    lsl.l    #2,D0            ;want it in bytes
  491.         lea    4(A0,D0.l),A0        ;skip symbol
  492.         move.l    (A0)+,D0        ;get longs to skip
  493.         bne.b    .SkipSymbol        ;do the next
  494.  
  495. .RemoveSymbol    tst.b    Symbol(A5)        ;want to remove hunk_symbol ?
  496.         beq    Loop            ;no,go back (parse next hunk)
  497.  
  498.         st    EFlag2(A5)        ;set flag,symbol_hunk removed
  499.  
  500.         exg.l    A0,A2            ;prepare work_register
  501.         bra    ShrinkFile        ;remove symbol hunk
  502.  
  503. * hunk_bss #(1003/$3EB) ***********************
  504.  
  505. ParseHunk04    addq.l    #4,A0            ;skip hunk_id
  506.  
  507. * hunk_break #(1014/$3F6) *********************
  508.  
  509. ParseHunk15                    ;same like hunk_end
  510.  
  511. * hunk_end #(1010/$3F2) ***********************
  512.  
  513. ParseHunk11    addq.l    #4,A0            ;skip hunk_id / bss_size
  514.         bra    Loop            ;go back (parse next hunk)
  515.  
  516. * hunk_overlay #(1013/$3F5) *******************
  517.  
  518. ParseHunk14    tst.b    EFlag1(A5)        ;only one overlay, please
  519.         bne    PrintError1        ;branch if not
  520.         st    EFlag1(A5)        ;set flag, overlay found
  521.  
  522.         movem.l    A0-1,-(SP)        ;save registers
  523.         bsr    PrintT05        ;print "contains overlay"
  524.         movem.l    (SP)+,A0-1        ;restore registers
  525.  
  526.         move.l    A0,OvlHunk(A5)        ;save base of overlay_hunk
  527.  
  528.         addq.l    #4,A0            ;skip hunk_id
  529.         move.l    (A0)+,D0        ;read hunk_size
  530.         move.l    (A0)+,D1        ;read max. tree_node
  531.         subq.l    #1,D1            ;prepare register
  532.         sub.l    D1,D0            ;skip tree_node buffers
  533.         subq.l    #1,D1            ;prepare dbra_loop
  534. .ChkOverlay    tst.l    (A0)+            ;node_buffers must be zero
  535.         bne    PrintError2        ;branch if not
  536.         dbra    D1,.ChkOverlay        ;check the next
  537.  
  538.         lsl.l    #2,D0            ;want it in bytes
  539.         lea    (A0,D0.l),A0        ;skip overlay_hunk
  540.         bra    Loop            ;go back (parse next hunk)
  541.  
  542. * hunk_header #(1011/$3F3) ********************
  543.  
  544. ParseHunk12    movea.l    A0,A2            ;save base
  545.  
  546.         addq.l    #4,A0            ;skip hunk_id
  547.         tst.l    (A0)+            ;must be 0 (resident libs)
  548.         bne    PrintError1        ;branch if not
  549.         addq.l    #4,A0            ;skip hunk counter
  550.         move.l    (A0)+,D1        ;read first hunk to load
  551.         move.l    (A0)+,D0        ;read last hunk to load
  552.         sub.l    D1,D0            ;calc buffers to skip
  553.         lsl.l    #2,D0            ;want it in bytes
  554.         lea    4(A0,D0.w),A0        ;skip buffers (hunk length)
  555.  
  556. ************************
  557.  
  558.         tst.b    EFlag1(A5)        ;overlay file ?
  559.         beq    Loop            ;no,go back (parse next hunk)
  560.  
  561.         movea.l    OvlHunk(A5),A3        ;get base (overlay_hunk)
  562.         addq.l    #4,A3            ;skip hunk_id
  563.         move.l    (A3)+,D0        ;read length in longs
  564.         move.l    (A3)+,D1        ;read tree_node
  565.         subq.l    #1,D1            ;prepare register
  566.         sub.l    D1,D0            ;skip tree_node buffers
  567.         subq.l    #1,D1            ;in case of dbra
  568. .ChkOverlay    tst.l    (A3)+            ;test tree_node buffers
  569.         bne    PrintError2        ;branch if not null
  570.         dbra    D1,.ChkOverlay        ;check all buffers
  571.  
  572.         move.l    RdSize(A5),D1        ;set rdsize upto current pos.
  573.         move.l    A2,D2            ;calculate overlay
  574.         sub.l    Memory(A5),D2        ;seekOffset for the
  575.         sub.l    D1,D2            ;current hunk_header
  576.  
  577. .SetSOffset    cmp.l    (A3),D2            ;search for ovl_seekOffset
  578.         bne.b    .SkipSOffset        ;branch if not the same
  579.         add.l    D1,(A3)            ;recalculate ovl_seekOffset
  580. .SkipSOffset    addq.l    #4,A3            ;skip seekOffset_buffer
  581.         tst.l    (A3)+            ;test dummy, must be zero
  582.         bne    PrintError2        ;branch if not
  583.         tst.l    (A3)+            ;test dummy, must be zero
  584.         bne    PrintError2        ;branch if not
  585.         adda.w    #20,A3            ;get next overlay_entry
  586.         subq.l    #8,D0            ;reduce hunk_length
  587.         bne.b    .SetSOffset        ;do for all entries
  588.         bra    Loop            ;go back (parse next hunk)
  589.  
  590. * hunk_reloc #(1004/$3EC) *********************
  591.  
  592. ParseHunk05    tst.b    Reloc32(A5)        ;want reloc32 ?
  593.         bne    Merge            ;branch if so
  594.  
  595. * extract drel32_entries **********************
  596.  
  597.         movea.l    A0,A2            ;set base of current hunk
  598.         movea.l    A1,A3            ;set destination area
  599.  
  600.         moveq    #11,D0            ;prepare register
  601.         add.l    (A2)+,D0        ;calculate new hunk_id
  602.         move.l    D0,(A3)+        ;and write
  603.  
  604.         moveq    #0,D3            ;clr counter (drel32_entries)
  605.         move.l    A3,A4            ;save buffer (# of drels)
  606.         move.l    (A2)+,D0        ;get # of relocs
  607.         beq.b    EndDRel32        ;branch if zero
  608.  
  609. SplitDRel32    move.w    D0,(A3)+        ;dummy_write # of drels
  610.         move.l    (A2)+,D1        ;get module #
  611.         move.w    D1,(A3)+        ;write module #
  612.         subq    #1,D0            ;prepare dbra_loop
  613.         moveq    #0,D2            ;clr counter (drel32_entries)
  614. NextDRel32    move.w    (A2)+,D1        ;check the high_word
  615.         bne.b    SkipReloc32        ;must be 0, skip
  616.         move.w    (A2),(A3)+        ;copy drel32
  617.         addq    #1,D2            ;inc. counter (drel32_entries)
  618. SkipReloc32    addq    #2,A2            ;skip low-word
  619.         dbra    D0,NextDRel32        ;do for all entries
  620.  
  621.         move.w    D2,(A4)            ;write new # of drels
  622.         bne.b    .NextModule        ;split next module
  623.         move.l    A4,A3            ;else, reset dest. address
  624. .NextModule    move.l    A3,A4            ;save buffer (# of drels)
  625.         add.l    D2,D3            ;add entries we found
  626.         move.l    (A2)+,D0        ;read entries of next module
  627.         bne.b    SplitDRel32        ;split next module if set
  628.  
  629. EndDRel32    move.l    D0,(A3)            ;write hunk_end
  630.  
  631. ***********************************************
  632.  
  633.         tst.l    D3            ;found some drels ?
  634.         beq.b    SkipHunk        ;branch if not
  635.  
  636.         addq    #2,A3            ;skip hunk_end
  637.         move.l    A3,D0            ;be sure it's long aligned
  638.         addq.l    #03,D0            ;calculate long_align
  639.         andi.b    #-4,D0            ;calculate long_align
  640.         move.l    D0,A3            ;reset dest. address
  641.  
  642.         move.l    A3,Buffer(A5)        ;set hunk end (drel32 only)
  643.  
  644. * extract reloc32_entries *********************
  645.  
  646.         movea.l    A0,A2            ;set reloc_hunk again
  647.  
  648.         move.l    (A2)+,(A3)+        ;copy hunk_id (reloc32)
  649.  
  650.         moveq    #0,D4            ;clear counter (reloc32)
  651.         movea.l    A3,A4            ;save buffer (# of relocs)
  652.         move.l    (A2)+,D0        ;read # of relocs
  653.         beq.b    EndReloc32        ;branch if zero
  654.  
  655. SplitReloc32    move.l    D0,(A3)+        ;dummy_write # of relocs
  656.         move.l    (A2)+,(A3)+        ;copy module #
  657.         subq    #1,D0            ;prepare dbra_loop
  658.         moveq    #0,D2            ;clear counter (reloc32)
  659. NextReloc32    move.w    (A2)+,D1        ;check high word
  660.         beq.b    SkipDRel32        ;branch if drel32
  661.         move.w    D1,(A3)+        ;copy high word
  662.         move.w    (A2),(A3)+        ;copy low word
  663.         addq    #1,D2            ;inc. counter (reloc32)
  664. SkipDRel32    addq    #2,A2            ;reset source address
  665.         dbra    D0,NextReloc32        ;do for all relocs
  666.  
  667.         move.l    D2,(A4)            ;write new # of relocs
  668.         bne.b    .NextModule        ;split next module
  669.         move.l    A4,A3            ;reset dest. address
  670. .NextModule    move.l    A3,A4            ;save buffer (# of relocs)
  671.         add.l    D2,D4            ;add entries we found
  672.         move.l    (A2)+,D0        ;read next # of relocs
  673.         bne.b    SplitReloc32        ;do next module if set
  674.  
  675. EndReloc32    move.l    D0,(A3)+        ;write hunk_end
  676.  
  677. ************************
  678.  
  679.         tst.l    D4            ;found some relocs ?
  680.         beq.b    GenerateReloc        ;branch if not
  681.  
  682.         move.l    A3,Buffer(A5)        ;set hunk end (both joined)
  683.  
  684.         tst.b    Split(A5)        ;want to split ?
  685.         beq.b    SkipHunk        ;branch if not
  686.         moveq    #6,D0            ;requires more than 5 drels
  687.         cmp.l    D0,D3            ;check for more
  688.         bls.b    SkipHunk        ;branch if not
  689.  
  690. GenerateReloc    tst.b    DRel32(A5)        ;want short_relocs ?
  691.         bne.b    SetDrel32        ;branch if so
  692.  
  693. SkipHunk    tst.b    Sort(A5)        ;want to sort ?
  694.         bne    SortReloc32        ;branch if so
  695.         movea.l    A2,A0            ;reset parsing pointer
  696.         bra    Loop            ;go parse next hunk
  697.  
  698. ************************
  699.  
  700. SetDrel32    st    EFlag3(A5)        ;set flag (file changed)
  701.  
  702.         move.l    Buffer(A5),D1        ;set hunk end (drel/joined)
  703.         sub.l    A1,D1            ;calculate hunk size
  704.         lsr.l    #2,D1            ;requires longs
  705.  
  706.         move.l    A0,-(SP)        ;save current parsing pointer
  707.  
  708.         movea.l    A1,A3            ;set base new hunk
  709. .ReplaceHunk    move.l    (A3)+,(A0)+        ;replace hunk
  710.         subq.l    #1,D1            ;long by long
  711.          bne.b    .ReplaceHunk        ;until zero
  712.  
  713.         move.l    A0,D0            ;calculate size
  714.         sub.l    A2,D0            ;to shrink
  715.         add.l    D0,RdSize(A5)        ;add (reduced)size [over all]
  716.  
  717.         movea.l    A2,A3            ;calculate new
  718.         adda.l    D0,A3            ;parsing pointer
  719.  
  720. .Shrink        move.l    (A2),(A2,D0.l)        ;shrink file
  721.         addq.l    #4,A2            ;long by long
  722.         cmpa.l    A2,A1            ;until eof
  723.         bne.b    .Shrink
  724.  
  725.         adda.l    D0,A1            ;file is now bit smaller
  726.  
  727.         movea.l    (SP)+,A0        ;restore current parsing ptr.
  728.  
  729.         tst.b    Sort(A5)        ;want to sort ?
  730.         bne.b    SortDRel32        ;branch if so
  731.  
  732.         movea.l    A3,A0            ;reset parsing pointer
  733.         bra    Loop            ;go back (parse next hunk)
  734.  
  735. * hunk_drel32 #(1015/$3F7) ********************
  736.  
  737. ParseHunk16
  738.  
  739. * hunk_reloc32short #(1020/$3FC) **************
  740.  
  741. ParseHunk21    tst.b    Reloc32(A5)        ;want to revert ?
  742.         bne.b    Merge            ;branch if so
  743.         tst.b    Sort(A5)        ;want to sort ?
  744.         bne.b    SortDRel32        ;branch if so
  745.  
  746.         addq.l    #4,A0            ;skip hunk_id
  747.         move.w    (A0)+,D0        ;get words to skip
  748.         beq.b    .align4            ;branch if zero
  749.  
  750. .SkipDRel    add.w    D0,D0            ;want it in bytes
  751.         lea    2(A0,D0.w),A0        ;jump to the next module
  752.         move.w    (A0)+,D0        ;get words to skip
  753.         bne.b    .SkipDRel        ;do until eoh
  754.  
  755. .align4        move.l    A0,D0            ;be sure, it's long aligned
  756.         addq.l    #03,D0            ;calculate long_align
  757.         andi.b    #-4,D0            ;calculate long_align
  758.         movea.l    D0,A0            ;reset parsing pointer
  759.         bra    Loop            ;go back (parse next hunk)
  760.  
  761. ***********************************************  sort relocs (16 bit) *******
  762.  
  763. * thanks dear thomas for the sort_part. i'm sure you will
  764. * read this. if so, send an email!!! :))
  765.  
  766. SortDRel32    addq.l    #4,a0            ;skip hunk_id
  767.         move.w    (A0)+,D0        ;set # of relocs
  768.         beq.b    .QuitSort        ;branch if zero
  769.  
  770. .SortModule    addq.l    #2,A0            ;skip # module
  771.         move.w    D0,D1            ;set # of relocs
  772.         lsr.w    #1,D1            ;calculate 1/2 of
  773.  
  774. .Sort        move.w    D1,D2            ;prepare register
  775.         move.w    D1,D3            ;prepare register
  776.         sub.w    D0,D2            ;calculate loop_counter
  777.         movea.l    A0,A2            ;set module base
  778.         lsl.w    #1,D3            ;want 1/2 of in bytes
  779.         lea    (A2,D3.W),A3        ;set base of destination
  780.         moveq    #0,D3            ;clear sort_flag
  781. .CheckEntry    cmpm.w    (A2)+,(A3)+        ;compare entries
  782.         bcc.b    .SkipEntry        ;branch if source lower
  783.         move.w    -2(A2),D4        ;swap entries
  784.         move.w    -2(A3),-2(A2)        ;swap entries
  785.         move.w    D4,-2(A3)        ;swap entries
  786.         st    D3            ;set flag (some sorted)
  787.         st    EFlag3(A5)        ;set flag (file changed)
  788. .SkipEntry    addq.w    #1,D2            ;increment loop counter
  789.         bmi.b    .CheckEntry        ;do until zero
  790.  
  791.         tst.b    D3            ;sorted some bytes ?
  792.         bne.b    .Sort            ;if so, sort part again!
  793.  
  794.         lsr.w    #1,D1            ;increment sort_range
  795.         bne.b    .Sort            ;sort next part until zero
  796.  
  797.         move.l    A3,A0            ;get next module
  798.         move.w    (A0)+,D0        ;get # of relocs
  799.         bne.b    .SortModule        ;sort next when set!
  800.  
  801. .QuitSort    move.l    A0,D0            ;be sure, it's long aligned
  802.         addq.l    #03,D0            ;calculate long_align
  803.         andi.b    #-4,D0            ;calculate long_align
  804.         movea.l    D0,A0            ;reset parsing pointer
  805.         bra    Loop            ;go back (parse next hunk)
  806.  
  807. *****************************************************************************
  808.  
  809. Merge        movea.l    A0,A2            ;prepare work_register
  810.         movea.l    A1,A3            ;prepare work_register
  811.  
  812.         moveq    #0,D1            ;prepare work_register
  813.         moveq    #0,D7            ;prepare work_register
  814.  
  815.         move.l    #$3EC,(A3)+        ;set hunk_id (reloc32)
  816.  
  817. ************************
  818.  
  819. CheckMerge    pea    CheckMerge(pc)        ;set return_address
  820.  
  821.         move.l    (A2)+,D0        ;get hunk_id
  822.  
  823.         cmp.w    #$3EC,D0        ;check for reloc32
  824.         beq.w    CopyReloc32        ;branch if so
  825.  
  826.         cmp.w    #$3F7,D0        ;check for drel32 (2.00+)
  827.         beq.w    CopyDRel32        ;branch if so
  828.  
  829.         cmp.w    #$3FC,D0        ;check for true drel32
  830.         beq.w    CopyDRel32        ;branch if so
  831.  
  832.         addq    #4,SP            ;remove return_address
  833.  
  834. ************************
  835.  
  836.         subq.l    #4,A2            ;restore base
  837.         addq.l    #4,A3            ;restore base
  838.  
  839.         tst.l    D1            ;found some hunks?
  840.         beq.b    QuitMerge        ;branch if not
  841.  
  842.         tst.b    D7            ;found some drel32_hunks?
  843.         bne.b    MergeHunks        ;branch if so
  844.  
  845. QuitMerge    tst.b    Sort(A5)        ;want to sort relocs?
  846.         bne.b    SortReloc32        ;branch if so
  847.         movea.l    A2,A0            ;reset parsing pointer
  848.         bra    Loop            ;go back (parse next hunk)
  849.  
  850. ************************************************
  851.  
  852. MergeHunks    subq.l    #1,D1            ;found only one hunk?
  853.         beq.b    AddFile            ;branch if so
  854.  
  855.         move.l    A2,-(SP)        ;save register
  856.         bsr    MergeModules        ;merge all modules
  857.         move.l    (SP)+,A2        ;restore register
  858.  
  859. AddFile        move.l    A2,D0            ;calc length (old reloc_hunk)
  860.         sub.l    A0,D0            ;calc length (old reloc_hunk)
  861.         move.l    A3,D1            ;calc length (new reloc_hunk)
  862.         sub.l    A1,D1            ;calc length (new reloc_hunk)
  863.  
  864. AddPart        move.l    (A2)+,(A3)+        ;join rest of datas
  865.         cmp.l    A2,A1            ;upto eof
  866.         bne.b    AddPart            ;do until!
  867.  
  868.         move.l    A3,D2            ;calc length (new reloc_hunk)
  869.         sub.l    A1,D2            ;+ rest of file
  870.         lsr.l    #2,D2            ;want it in longwords
  871.         movea.l    A0,A2            ;set destination
  872.         movea.l    A1,A3            ;set source
  873. ReplacePart    move.l    (A3)+,(A2)+        ;overwrite old reloc_hunk
  874.         subq.l    #1,D2            ;replace by the new one
  875.         bne.b    ReplacePart        ;do it until eof
  876.  
  877.         st    EFlag3(A5)        ;set flag (file changed)
  878.  
  879.         sub.l    D1,D0            ;calc new file_length
  880.         sub.l    D0,RdSize(A5)        ;calc new file_length
  881.         movea.l    A2,A1            ;set new file_end
  882.  
  883.         tst.b    Sort(A5)        ;want to sort relocs?
  884.         bne.b    SortReloc32        ;branch if so
  885.  
  886.         adda.l    D1,A0            ;reset parsing pointer
  887.         bra    Loop            ;go back (parse next hunk)
  888.  
  889. ***********************************************  sort relocs (32 bit) *******
  890.  
  891. SortReloc32    addq.l    #4,A0            ;skip hunk_id
  892.         move.l    (A0)+,D0        ;set # of relocs
  893.         beq.b    .QuitSort        ;branch if zero
  894.  
  895. .SortModule    addq.l    #4,A0            ;skip # module
  896.         move.l    D0,D1            ;set # of relocs
  897.         lsr.l    #1,D1            ;calculate 1/2 of
  898.  
  899. .Sort        move.l    D1,D2            ;prepare register
  900.         move.l    D1,D3            ;prepare register
  901.         sub.l    D0,D2            ;calculate loop_counter
  902.         movea.l    A0,A2            ;set module base
  903.         lsl.l    #$2,D3            ;want 1/2 of in bytes
  904.         lea    (A2,D3.L),A3        ;set base of destination
  905.         moveq    #0,D3            ;clear sort_flag
  906. .CheckEntry    cmpm.l    (A2)+,(A3)+        ;compare entries
  907.         bcc.b    .SkipEntry        ;branch if source lower
  908.         move.l    -4(A2),D4        ;swap entries
  909.         move.l    -4(A3),-4(A2)        ;swap entries
  910.         move.l    D4,-4(A3)        ;swap entries
  911.         st    D3            ;set flag (some sorted)
  912.         st    EFlag3(A5)        ;set flag file changed
  913. .SkipEntry    addq.l    #1,D2            ;increment loop counter
  914.         bmi.b    .CheckEntry        ;do until zero
  915.  
  916.         tst.b    D3            ;sorted some bytes ?
  917.         bne.b    .Sort            ;if so, sort part again!
  918.  
  919.         lsr.l    #1,D1            ;increment sort_range
  920.         bne.b    .Sort            ;sort next part until zero
  921.  
  922.         move.l    A3,A0            ;get next module
  923.         move.l    (A0)+,D0        ;get # of relocs
  924.         bne.b    .SortModule        ;sort next when set!
  925.  
  926. .QuitSort    bra    Loop            ;else, go back
  927.  
  928. *****************************************************************************
  929.  
  930. MergeModules    moveq    #0,D0            ;set module # to search for
  931.         moveq    #0,D4            ;clear merge_flag
  932.         movea.l    A1,A2            ;set base of reloc_hunk
  933.         addq.l    #4,A2            ;skip hunk_id
  934.  
  935. .SearchModule1    move.l    A2,D3            ;prepare module_size
  936.         move.l    (A2)+,D1        ;get # of relocs
  937.  
  938. .SearchModule2    move.l    (A2)+,D2        ;get module #
  939.         cmp.l    D0,D2            ;we search for?
  940.         beq.b    .CopyModule        ;branch if so
  941.  
  942. .SkipModule    lsl.l    #2,D1            ;want size in bytes
  943.         lea    (A2,D1.l),A2        ;skip module
  944.         move.l    A2,D3            ;save base (current module)
  945.         move.l    (A2)+,D1        ;get # of relocs
  946.         beq.b    .MergeNextMod        ;branch, no more modules
  947.  
  948.         move.l    (A2)+,D2        ;get module #
  949.         cmp.l    D0,D2            ;we search for?
  950.         bne.b    .SkipModule        ;branch if not
  951.  
  952. .CopyModule    tst.b    D4            ;test merge_flag
  953.         bne.b    .JoinModule        ;join module if set
  954.  
  955.         movea.l    A3,A4            ;save buffer (# relocs)
  956.         move.l    D4,(A3)+        ;clear # of relocs
  957.         move.l    D2,(A3)+        ;set module #
  958.         st    D4            ;set flag (next must joined)
  959.  
  960. .JoinModule    add.l    D1,(A4)            ;increment # of relocs
  961. .CopyEntry    move.l    (A2)+,(A3)+        ;copy relocs
  962.         subq.l    #1,D1            ;decrement counter
  963.         bne.b    .CopyEntry        ;do until zero
  964.  
  965.         sub.l    A2,D3            ;calculate module length
  966.         move.l    A2,-(SP)        ;save register
  967. .DeleteModule    move.l    (A2),(A2,D3.l)        ;replace rest of reloc_hunk
  968.         addq.l    #4,A2            ;long by long
  969.         cmpa.l    A2,A3            ;do until
  970.         bne.b    .DeleteModule        ;end of hunk
  971.         movea.l    (SP)+,A2        ;restore register
  972.  
  973.         adda.l    D3,A2            ;reset address (next module)
  974.         adda.l    D3,A3            ;reset destination area
  975.         adda.l    D3,A4            ;reset ptr. (# of relocs)
  976.  
  977.         move.l    A2,D3            ;save base (next module)
  978.         move.l    (A2)+,D1        ;get # of relocs
  979.         bne.b    .SearchModule2        ;branch if set
  980.  
  981. .MergeNextMod    addq.l    #1,D0            ;inc. module # to search for
  982.         moveq    #0,D4            ;clear merge_flag
  983.         movea.l    A1,A2            ;get base of reloc_hunk
  984.         addq.l    #4,A2            ;skip hunk_id
  985.         move.l    (A2),(A3)        ;all modules merged ?
  986.         bne.b    .SearchModule1        ;branch if not
  987.  
  988.         addq.l    #4,A2            ;skip hunk_end
  989. .ResetNewHunk    move.l    (A2),-4(A2)        ;reset merged reloc_hunk
  990.         addq.l    #4,A2            ;long by long
  991.         cmp.l    A3,A2            ;until
  992.         bls.b    .ResetNewHunk        ;end of hunk
  993.         rts                ;go back
  994.  
  995. *****************************************************************************
  996.  
  997. CopyDRel32    moveq    #0,D0            ;prepare register
  998.         moveq    #0,D2            ;prepare register
  999.         move.w    (A2)+,D0        ;get # of relocs
  1000.         beq.b    .SetEndMark        ;branch if zero
  1001. .CopyModule    move.l    D0,(A3)+        ;set # of relocs
  1002.         move.w    (A2)+,D2        ;get module #
  1003.         move.l    D2,(A3)+        ;write as long
  1004. .CopyReloc    move.w    (A2)+,D2        ;get reloc
  1005.         move.l    D2,(A3)+        ;write as long
  1006.         subq.l    #1,D0            ;decrement reloc_counter
  1007.         bne.b    .CopyReloc        ;do until zero
  1008.         move.w    (A2)+,D0        ;get # of relocs
  1009.         bne.b    .CopyModule        ;branch, copy module
  1010.         addq.l    #1,D1            ;increment # of hunks copied
  1011.         st    D7            ;flag, found drel32_hunk
  1012. .SetEndMark    move.l    D0,(A3)            ;set end_mark (zero)
  1013.         move.l    A2,D0            ;be sure, we are long aligned
  1014.         addq.l    #03,D0            ;calculate long_align
  1015.         andi.b    #-4,D0            ;calculate long_align
  1016.         movea.l    D0,A2            ;reset end_address
  1017.         rts                ;go back
  1018.  
  1019. *****************************************************************************
  1020.  
  1021. CopyReloc32    move.l    (A2)+,D0        ;get # of relocs
  1022.         beq.b    .SetEndMark        ;branch if zero
  1023. .CopyModule    move.l    D0,(A3)+        ;copy # of relocs
  1024.         move.l    (A2)+,(A3)+        ;copy module number
  1025. .CopyReloc    move.l    (A2)+,(A3)+        ;copy entry
  1026.         subq.l    #1,D0            ;decrement counter
  1027.         bne.b    .CopyReloc        ;do for all entries
  1028.         move.l    (A2)+,D0        ;get # of relocs
  1029.         bne.b    .CopyModule        ;branch, copy next module
  1030.         addq.l    #1,D1            ;increment # of hunks copied
  1031. .SetEndMark    move.l    D0,(A3)            ;set end_mark (zero)
  1032.         rts                ;go back
  1033.  
  1034. ***********************************************  save file to disk **********
  1035.  
  1036. SaveFile    moveq    #0,D4            ;initialize own error code
  1037.  
  1038.         bsr    PresetBFName        ;set backup filename
  1039.  
  1040.         move.l    SPath(A5),D1        ;set pathpart
  1041.         beq.b    MakeBackup        ;use current dir. if unset
  1042.  
  1043.         moveq    #ACCESS_READ,D2        ;set lock option
  1044.         jsr    _LVOLock(A6)        ;use DOS to (lock) dir.
  1045.         move.l    D0,SPLock(A5)        ;save lock
  1046.         beq.b    SaveError        ;branch on lock error
  1047.  
  1048.         move.l    D0,D1            ;set lock
  1049.         jsr    _LVOCurrentDir(A6)    ;use DOS to set (currentdir)
  1050.         move.l    D0,OldSDir(A5)        ;save lock (prev. directory)
  1051.  
  1052. MakeBackup    lea    BName(A5),A1        ;get filename (backup)
  1053.         move.l    A1,D1            ;set filename
  1054.         jsr    _LVODeleteFile(A6)    ;use DOS to (deletefile)
  1055.  
  1056.         lea    SName(A5),A0        ;get filename (save)
  1057.         lea    BName(A5),A1        ;get filename (backup)
  1058.         move.l    A0,D1            ;set oldname
  1059.         move.l    A1,D2            ;set newname
  1060.         jsr    _LVORename(A6)        ;use DOS to (rename) file
  1061.  
  1062.         lea    SName(A5),A1        ;get filename
  1063.         move.l    A1,D1            ;set filename
  1064.         move.l    #MODE_NEWFILE,D2    ;want open a new file
  1065.         jsr    _LVOOpen(A6)        ;use DOS to (open) file
  1066.         move.l    D0,FHandleS(A5)        ;save filehandle
  1067.         beq.b    SaveError        ;branch on failure
  1068.  
  1069.         move.l    D0,D1            ;set filehandle
  1070.         move.l    Memory(A5),D2        ;set buffer
  1071.         move.l    NFSize(A5),D3        ;set length
  1072.         jsr    _LVOWrite(A6)        ;use DOS to (write) file
  1073.         move.l    D0,D2            ;save success value
  1074.  
  1075.         move.l    FHandleS(A5),D1        ;set filehandle
  1076.         jsr    _LVOClose(A6)        ;use DOS to (close) file
  1077.  
  1078.         tst.l    D2            ;check for success
  1079.         bmi.b    SaveError        ;branch if not
  1080.  
  1081.         move.w    #207,D4            ;preset (seek error)
  1082.         cmp.l    D2,D3            ;all bytes written ?
  1083.         beq.b    QuitSaveFile        ;branch if so
  1084.  
  1085. ***********************************************
  1086.  
  1087. SaveError    st    EFlag4(A5)        ;set flag (save error)
  1088.  
  1089.         bsr    PrintError0        ;print some information
  1090.  
  1091.         addq.l    #4,SP            ;clear old return address
  1092.         pea    Main3(pc)        ;set new one
  1093.  
  1094.         lea    SName(A5),A1        ;get filename
  1095.         move.l    A1,D1            ;set filename
  1096.         jsr    _LVODeleteFile(A6)    ;delete corrupt file
  1097.  
  1098.         lea    BName(A5),A0        ;get filename (backup)
  1099.         lea    SName(A5),A1        ;get filename (save)
  1100.         move.l    A0,D1            ;set oldname
  1101.         move.l    A1,D2            ;set newname
  1102.         jsr    _LVORename(A6)        ;use DOS to (rename) file
  1103.  
  1104. ***********************************************
  1105.  
  1106. QuitSaveFile    tst.b    EFlag4(A5)        ;save error ?
  1107.         bne.b    ResetSDir        ;branch if so
  1108.  
  1109.         tst.b    Replace(A5)        ;want to replace ?
  1110.         beq.b    SetProtect        ;branch if not
  1111.  
  1112.         tst.b    EFlag1(A5)        ;is it overlay ?
  1113.         bne.b    SetProtect        ;if so, force backup
  1114.  
  1115.         tst.b    EFlag2(A5)        ;removed some hunks/zeros ?
  1116.         bne.b    SetProtect        ;if so, force backup
  1117.  
  1118.         lea    BName(A5),A1        ;get filename
  1119.         move.l    A1,D1            ;set filename
  1120.         jsr    _LVODeleteFile(A6)    ;use DOS to (deletefile)
  1121.  
  1122. SetProtect    lea    SName(A5),A3        ;get filename
  1123.         move.l    A3,D1            ;set filename
  1124.         lea    FIBlock(A5),A2        ;get fileinfoblock
  1125.         move.l    fib_Protection(A2),D2    ;set protection bits
  1126.         bclr    #FIBB_ARCHIVE,D2    ;clear archive bit
  1127.         jsr    _LVOSetProtection(A6)    ;use DOS to (setprotection)
  1128.  
  1129.         tst.b    fib_Comment(A2)        ;is there a comment ?
  1130.         beq.b    ResetSDir        ;branch if not
  1131.  
  1132.         move.l    A3,D1            ;set filename
  1133.         lea    fib_Comment(A2),A2    ;get comment
  1134.         move.l    A2,D2            ;set comment
  1135.         jsr    _LVOSetComment(A6)    ;use DOS to (setcomment)
  1136.  
  1137. ResetSDir    move.l    OldSDir(A5),D1        ;set former directory
  1138.         beq.b    UnLockSDir        ;branch if not set
  1139.         jsr    _LVOCurrentDir(A6)    ;use DOS to set (currentdir)
  1140.  
  1141. UnLockSDir    move.l    SPLock(A5),D1        ;set dir. lock
  1142.         beq.b    QuitSave        ;branch if not set
  1143.         jsr    _LVOUnLock(A6)        ;use DOS to (unlock) dir.
  1144. QuitSave    rts                ;go back
  1145.  
  1146. ***********************************************  preset backup name *********
  1147.  
  1148. PresetBFName    moveq    #-1,D0            ;prepare char counter
  1149.         lea    SName(A5),A0        ;get savename buffer
  1150.         lea    BName(A5),A1        ;get backup buffer
  1151.         lea    Suffix(pc),A2        ;get suffix
  1152. GetFNChar    addq.l    #1,D0            ;add char counter
  1153.         move.b    (A0)+,(A1)+        ;copy char
  1154.         bne.b    GetFNChar        ;do it for all chars
  1155.         subq.l    #1,A1            ;restore address
  1156.  
  1157. AddSuffix    sub.b    #26,D0            ;is there room for suffix?
  1158.         bmi.b    SetSuffix        ;branch if so
  1159.         suba.l    D0,A1            ;else, reduce stringsize
  1160. SetSuffix    move.b    (A2)+,(A1)+        ;append extender
  1161.         bne.b    SetSuffix        ;until zero
  1162. QuitSetName    rts                ;go back
  1163.  
  1164. *****************************************************************************
  1165.  
  1166. Suffix        dc.b    ".bak",0,0
  1167.  
  1168. ***********************************************  load file to memory ********
  1169.  
  1170. LoadFile    moveq    #0,D4            ;initialize own error code
  1171.  
  1172.         move.l    LPLock(A5),D1        ;get dir. lock, preset by ASL
  1173.         bne.b    GetDir            ;branch if set
  1174.  
  1175.         move.l    LPath(A5),D1        ;set pathpart
  1176.         beq.b    GetFile            ;use currentdir if unset
  1177.  
  1178.         moveq    #ACCESS_READ,D2        ;set lock option
  1179.         jsr    _LVOLock(A6)        ;use DOS to (lock) dir.
  1180.         move.l    D0,LPLock(A5)        ;save lock
  1181.         beq    LoadError        ;branch on failure
  1182.  
  1183.         move.l    D0,D1            ;set lock
  1184.  
  1185. GetDir        jsr    _LVOCurrentDir(A6)    ;use DOS to set (currentdir)
  1186.         move.l    D0,OldLDir(A5)        ;save lock (prev. directory)
  1187.  
  1188. GetFile        lea    LName(A5),A1        ;get filename
  1189.         move.l    A1,D1            ;set filename
  1190.         move.l    #MODE_OLDFILE,D2    ;want open an existing file
  1191.         jsr    _LVOOpen(A6)        ;use DOS to (open) file
  1192.         move.l    D0,FHandleL(A5)        ;save filehandle
  1193.         beq.b    LoadError        ;branch on failure
  1194.  
  1195. ***********************************************
  1196.  
  1197.         move.l    D0,D1            ;set filehandle
  1198.         lea    ProgID(A5),A2        ;get buffer (8 bytes)
  1199.         move.l    A2,D2            ;set base
  1200.         moveq    #8,D3            ;set size
  1201.         jsr    _LVORead(A6)        ;use DOS to (read) bytes
  1202.         tst.l    D0            ;test for success
  1203.         bmi.b    LoadError        ;branch if not
  1204.  
  1205. ***********************************************
  1206.  
  1207.         move.w    #305,D4            ;preset io_error (not exec.)
  1208.  
  1209.         cmp.l    D0,D3            ;8 bytes loaded ?
  1210.         bne.b    LoadError        ;branch if not?!?! hmmm...
  1211.  
  1212.         cmp.l    #HUNK_HEADER,(A2)    ;check for executable
  1213.         bne.b    LoadError        ;branch if not
  1214.         tst.l    4(A2)            ;check for executable
  1215.         bne.b    LoadError        ;branch if not
  1216.  
  1217. ***********************************************
  1218.  
  1219.         move.l    FHandleL(A5),D1        ;set filehandle
  1220.         lea    FIBlock(A5),A3        ;get fileinfoblock
  1221.         move.l    A3,D2            ;set fib
  1222.         jsr    _LVOExamineFH(A6)    ;use DOS to (examinefh)
  1223.         tst.l    D0            ;test for success
  1224.         beq.b    LoadError        ;branch if not
  1225.  
  1226.         move.l    fib_Size(A3),D0        ;set filesize
  1227.         add.l    D0,D0            ;add working area
  1228.         moveq    #0,D1            ;no memory options
  1229.         movea.l    4.w,A6            ;set EXEC to call a function
  1230.         jsr    _LVOAllocMem(A6)    ;use EXEC to (allocmem)
  1231.  
  1232.         movea.l    DOSBase(A5),A6        ;set DOS to call a function
  1233.  
  1234.         move.l    D0,Memory(A5)        ;save memorybase
  1235.         beq.b    LoadError        ;branch when no free store
  1236.  
  1237. ***********************************************
  1238.  
  1239.         movea.l    D0,A0            ;set membase
  1240.         move.l    (A2)+,(A0)+        ;copy hunk_id
  1241.         move.l    (A2)+,(A0)+        ;copy hunk_id
  1242.  
  1243.         move.l    FHandleL(A5),D1        ;set filehandle
  1244.         move.l    A0,D2            ;set membase
  1245.         move.l    fib_Size(A3),D3        ;set filesize
  1246.         subq.l    #8,D3            ;skip hunk_id
  1247.         beq.b    LoadError        ;no more bytes?!?! hmmm...
  1248.         jsr    _LVORead(A6)        ;use DOS to (read) bytes
  1249.         tst.l    D0            ;test for success
  1250.         bmi.b    LoadError        ;branch if not
  1251.  
  1252.         move.w    #219,D4            ;preset io_error (seek error)
  1253.  
  1254.         cmp.l    D0,D3            ;got we all bytes ?
  1255.         beq.b    CloseLFile        ;branch if so
  1256.  
  1257. ***********************************************
  1258.  
  1259. LoadError    bsr.b    PrintError0        ;print error information
  1260.  
  1261.         addq.l    #4,SP            ;clear old return address
  1262.         pea    Main3(pc)        ;set new return address
  1263.  
  1264. ***********************************************
  1265.  
  1266. CloseLFile    move.l    FHandleL(A5),D1        ;set filehandle
  1267.         beq.b    ResetDir        ;branch if not set
  1268.         jsr    _LVOClose(A6)        ;use DOS to (close) file
  1269.  
  1270. ResetDir    move.l    OldLDir(A5),D1        ;set former directory
  1271.         beq.b    UnLockLDir        ;branch if not set
  1272.         jsr    _LVOCurrentDir(A6)    ;use DOS to set (currentdir)
  1273.  
  1274. UnLockLDir    tst.b    ASLFlag(A5)        ;got file by ASL ?
  1275.         bne.b    QuitLoad        ;branch if so
  1276.         move.l    LPLock(A5),D1        ;set dir. lock
  1277.         beq.b    QuitLoad        ;branch if not set
  1278.         jsr    _LVOUnLock(A6)        ;use DOS to (unlock) dir.
  1279. QuitLoad    rts                ;go back
  1280.  
  1281. ***********************************************  print hunk error ***********
  1282.  
  1283. PrintError2    addq    #4,SP            ;clear old return address
  1284.         pea    Main3(pc)        ;set new one
  1285.  
  1286.         moveq    #0,D5            ;prepare register
  1287.         moveq    #0,D4            ;prepare register
  1288.         move.w    #212,D4            ;set error code (wrong type)
  1289.         bra.b    PrintFailed0        ;print error information
  1290.  
  1291. ***********************************************  print hunk error ***********
  1292.  
  1293. PrintError1    addq    #4,SP            ;clear old return address
  1294.         pea    Main3(pc)        ;set new one
  1295.  
  1296.         moveq    #0,D5            ;prepare register
  1297.         moveq    #0,D4            ;prepare register
  1298.         move.w    #235,D4            ;set error code (bad hunk)
  1299.         bra.b    PrintFailed0        ;print error information
  1300.  
  1301. ***********************************************  get load/save error ********
  1302.  
  1303. PrintError0    jsr    _LVOIoErr(A6)        ;use DOS to get (io_error)
  1304.         move.l    D0,D5            ;save io_error
  1305.  
  1306. ***********************************************  print error information ****
  1307.  
  1308. PrintFailed0    move.b    Quiet(A5),D0        ;test quiet-flag
  1309.         beq.b    PrintFailed1        ;branch if unset
  1310.         bsr.b    PrintET01        ;print filename first
  1311.  
  1312.         move.b    EFlag1(A5),D0        ;test for overlay found
  1313.         beq.b    PrintFailed2        ;branch if unset
  1314.         bsr.b    PrintET05        ;print text "contains ovl."
  1315.  
  1316. PrintFailed2    move.b    EFlag4(A5),D0        ;test for saving file
  1317.         beq.b    PrintFailed1        ;branch if unset
  1318.         bsr.b    PrintET02        ;print text "writing"
  1319.  
  1320. PrintFailed1    bsr.b    PrintET03        ;print text "*** FAILED ***"
  1321.  
  1322.         move.l    D5,D1            ;set io_error
  1323.         bgt.b    PrintFault2        ;branch if one
  1324.  
  1325.         move.l    D4,D1            ;force own error
  1326.  
  1327. PrintFault2    move.l    D1,IOErr(A5)        ;save io_error
  1328.         lea    Header2(pc),A0        ;get header text
  1329.         move.l    A0,D2            ;set header text
  1330.         jsr    _LVOPrintFault(A6)    ;use DOS to (printfault)
  1331.  
  1332.         moveq    #1,D0            ;set failat level
  1333.         add.l    D0,RCode(A5)        ;set returncode
  1334.         rts                ;go back / go main3
  1335.  
  1336. ***********************************************  print some information *****
  1337.  
  1338. PrintET05    lea    Text05(pc),A0        ;get text "contains overlay"
  1339.         bra.b    PrintText0        ;and print
  1340.  
  1341. PrintET03    lea    Text03(pc),A0        ;get text "*** FAILED ***"
  1342.         bra.b    PrintText0        ;and print
  1343.  
  1344. PrintET02    lea    Text02(pc),A0        ;get text "writing"
  1345.         bra.b    PrintText0        ;and print
  1346.  
  1347. PrintET01    lea    Text01(pc),A0        ;get text "FILE:"
  1348.         bsr.b    PrintText0        ;and print
  1349.         lea    LName(A5),A0        ;get filename
  1350.         bra.b    PrintText0        ;and print
  1351.  
  1352. ***********************************************
  1353.  
  1354. PrintT06    lea    Text06(pc),A0        ;get text "untouched"
  1355.         bra.b    PrintText1        ;and print
  1356.  
  1357. PrintT05    lea    Text05(pc),A0        ;get text "contains overlay"
  1358.         bra.b    PrintText1        ;and print
  1359.  
  1360. PrintT04    lea    Text04(pc),A0        ;get text "done."
  1361.         bra.b    PrintText1        ;and print
  1362.  
  1363. PrintT02    lea    Text02(pc),A0        ;get text "writing"
  1364.         bra.b    PrintText1        ;and print
  1365.  
  1366. PrintT00    lea    Text00(pc),A0        ;get text "processing"
  1367.         bsr.b    PrintText1        ;and print
  1368.         lea    Text01(pc),A0        ;get text "FILE:"
  1369.         bsr.b    PrintText1        ;and print
  1370.         lea    LName(A5),A0        ;get filename
  1371.  
  1372. *********************************************** printtext (null-terminated) *
  1373.  
  1374. PrintText1    move.b    Quiet(A5),D0        ;test quiet-flag
  1375.         bne.b    QuitPrint        ;branch if set
  1376.  
  1377. ***********************************************
  1378.  
  1379. PrintText0    move.l    A0,D2            ;set text to print
  1380.         moveq    #-1,D3            ;prepare register
  1381. CalcSize    addq.l    #1,D3            ;calculate
  1382.         tst.b    (A0)+            ;text length
  1383.         bne.b    CalcSize        ;until null-byte
  1384.  
  1385.         jsr    _LVOOutput(A6)        ;use DOS to find (output)
  1386.         move.l    D0,D1            ;set output-handle
  1387.         jsr    _LVOWrite(A6)        ;use DOS to (write) text
  1388. QuitPrint    rts                ;go back
  1389.  
  1390. *********************************************** printtext (null-terminated) *
  1391.  
  1392. PrintTBS    move.b    Quiet(A5),D0        ;test quiet-flag
  1393.         bne.b    QuitPrintSB        ;branch if set
  1394.  
  1395.         lea    Text07(pc),A1        ;get text "%ld bytes "
  1396.         lea    RdSize(A5),A2        ;get buffer
  1397.         lea    Text09(pc),A3        ;get text "lost"
  1398.  
  1399.         tst.l    (A2)            ;saved some ?
  1400.         beq.b    QuitPrintSB        ;branch if not
  1401.         bpl.b    PrintSBytes        ;lost some ?
  1402.  
  1403.         neg.l    (A2)            ;need positive
  1404.         lea    Text08(pc),A3        ;get text "saved"
  1405.  
  1406. PrintSBytes    move.l    A1,D1            ;set text
  1407.         move.l    A2,D2            ;set argv
  1408.         jsr    _LVOVPrintf(A6)        ;use DOS to (vprintf)
  1409.  
  1410.         move.l    A3,D1            ;set text
  1411.         jsr    _LVOPutStr(A6)        ;use DOS to (putstr)
  1412.  
  1413.         jsr    _LVOOutput(A6)        ;use DOS to find (output)
  1414.         move.l    D0,D1            ;set output-handle
  1415.         jsr    _LVOFlush(A6)        ;use DOS to (flush) handle
  1416. QuitPrintSB    rts                ;go back
  1417.  
  1418. *****************************************************************************
  1419.  
  1420. Text00        dc.b    "processing",0
  1421. Text01        dc.b    " FILE: ",0
  1422. Text02        dc.b    ", writing...",0
  1423. Text03        dc.b    " *** FAILED ***",$A,0
  1424. Text04        dc.b    " done.",$A,0
  1425. Text05        dc.b    ", contains overlay",0
  1426. Text06        dc.b    ", untouched.",$A,0
  1427. Text07        dc.b    ", %ld bytes ",0
  1428. Text08        dc.b    "saved",0
  1429. Text09        dc.b    "lost",0
  1430.  
  1431. Header2        dc.b    "ERROR",0
  1432.  
  1433.         even
  1434.  
  1435. ***********************************************  prepare file/dir (dst.) ****
  1436.  
  1437. PrepSDst    move.l    LPath(A5),SPath(A5)    ;copy pathpart_ptr
  1438.  
  1439.         lea    LName(A5),A0        ;get buffer fname (load)
  1440.         lea    SName(A5),A1        ;set buffer fname (save)
  1441. SetSName    move.b    (A0)+,(A1)+        ;preset filename
  1442.         bne.b    SetSName        ;until zero
  1443.  
  1444.         move.l    SREQBase(A5),D1        ;set save_requester base
  1445.         bne.b    PrepSASL        ;branch if set
  1446.  
  1447.         move.l    SFile(A5),D2        ;check for dst. filename
  1448.         beq.b    QuitPrepSArg        ;branch if not set
  1449.  
  1450.         move.l    D1,SPath(A5)        ;clear pathpart_ptr
  1451.  
  1452.         move.l    D2,D1            ;set filename
  1453.         jsr    _LVOFilePart(A6)    ;use DOS to find (filepart)
  1454.  
  1455.         movea.l    D0,A0            ;set base of filename
  1456.         lea    SName(A5),A1        ;set buffer (max: 30 chars)
  1457.         bsr.b    CopyFName        ;copy filename
  1458.  
  1459.         cmp.l    D0,D2            ;is there a pathpart ?
  1460.         beq.b    QuitPrepSArg        ;branch if not
  1461.  
  1462.         move.l    D2,SPath(A5)        ;save pathpart_ptr
  1463.  
  1464. QuitPrepSArg    rts                ;go back
  1465.  
  1466. ***********************************************
  1467.  
  1468. PrepSASL    movea.l    D1,A2            ;set sreqbase
  1469.         movea.l    fr_Drawer(A2),A0    ;get pathpart
  1470.         tst.b    (A0)            ;is there one ?
  1471.         beq.b    GetSFASL        ;no, branch
  1472.  
  1473.         move.l    A0,SPath(A5)        ;set pathpart
  1474.  
  1475. GetSFASL    movea.l    fr_File(A2),A0        ;get filename
  1476.         tst.b    (A0)            ;is there one ?
  1477.         beq.b    QuitSFASL        ;no,branch
  1478.         lea    SName(A5),A1        ;set buffer
  1479.         bsr.b    CopyFName        ;copy filename
  1480. QuitSFASL    rts                ;go back
  1481.  
  1482. ***********************************************  prepare file/dir (src.) ****
  1483.  
  1484. PrepLSrc    move.l    FileCnt(A5),D0        ;get file counter
  1485.         move.l    ASLFlag(A5),D1        ;check for ASL
  1486.         bne.b    PrepLASL        ;branch if so
  1487.  
  1488. ************************************************
  1489.  
  1490. PrepLARG    lsl.l    #2,D0            ;use D0 as offset
  1491.  
  1492.         movea.l    LFile(A5),A2        ;set source list
  1493.         move.l    0(A2,D0.w),D2        ;get base of next filename
  1494.  
  1495.         move.l    D2,D1            ;set filename
  1496.         jsr    _LVOFilePart(A6)    ;use DOS to find (filepart)
  1497.  
  1498.         movea.l    D0,A0            ;set base of filename
  1499.         lea    LName(A5),A1        ;set buffer (max: 30 chars)
  1500.         bsr.b    CopyFName        ;copy filename
  1501.  
  1502.         cmp.l    D0,D2            ;is there a pathpart ?
  1503.         beq.b    QuitPrepLArg        ;branch if not
  1504.  
  1505.         move.l    D2,LPath(A5)        ;save pointer
  1506.  
  1507. QuitPrepLArg    rts                ;go back
  1508.  
  1509. ***********************************************  prepare asl filename *******
  1510.  
  1511. PrepLASL    lsl.l    #3,D0            ;use D0 as offset
  1512.  
  1513.         movea.l    LREQBase(A5),A2        ;get requester base
  1514.         movea.l    fr_ArgList(A2),A2    ;set filetable
  1515.         move.l    0(A2,D0.w),LPLock(A5)    ;copy lock
  1516.  
  1517.         movea.l    4(A2,D0.w),A0        ;set filename
  1518.         lea    LName(A5),A1        ;set buffer (max: 30 chars)
  1519.  
  1520. ***********************************************
  1521.  
  1522. CopyFName    move.b    (A0),(A1)+        ;copy first byte
  1523.         move.b    #0,(A0)+        ;set pathpart terminator
  1524. CopyChar    move.b    (A0)+,(A1)+        ;copy bytes (max: 30 chars)
  1525.         bne.b    CopyChar        ;until zero
  1526.         rts                ;go back
  1527.  
  1528. ***********************************************  check for break signal *****
  1529.  
  1530. ChkBreak    moveq    #00,D1            ;prepare signal mask
  1531.         bset    #12,D1            ;set break bit (ctrl_c)
  1532.         jsr    _LVOCheckSignal(A6)    ;use DOS to (checksignal)
  1533.         btst    #12,D0            ;test break bit (ctrl_c)
  1534.         bne    ForceFault3        ;if set, branch (set ioerr)
  1535.         rts                ;go back
  1536.  
  1537. ***********************************************  open asl requester (load) **
  1538.  
  1539. OpenREQs    tst.l    AslReq(A5)        ;test flag
  1540.         beq    ForceFault1        ;if unset, branch (arg miss.)
  1541.  
  1542.         move.l    ASLBase(A5),D6        ;is there ASL available ?
  1543.         beq    ForceFault4        ;print (invalid lib.) if not
  1544.  
  1545.         moveq    #0,D0            ;want a filerequester
  1546.         lea    ASLTAG_L(pc),A0        ;set taglist
  1547.  
  1548.         moveq    #1,D1            ;set tag item boolean value
  1549.         lea    Title_L2(pc),A1        ;get tag item req_title
  1550.  
  1551.         move.l    D1,12(A0)        ;set multiselect (true)
  1552.         move.l    A1,04(A0)        ;set req_title
  1553.         movea.l    D6,A6            ;set ASL to call a function
  1554.         jsr    _LVOAllocAslRequest(A6)    ;use ASL to (allocaslrequest)
  1555.  
  1556.         move.l    D0,LREQBase(A5)        ;save req_base
  1557.         beq    PrintFault0        ;branch on failure
  1558.  
  1559.         movea.l    D0,A0            ;set req_base
  1560.         suba.l    A1,A1            ;no more tags yet
  1561.         jsr    _LVOAslRequest(A6)    ;use ASL to open (aslrequest)
  1562.         tst.l    D0            ;test result
  1563.         beq    PrintFault0        ;branch on failure
  1564.  
  1565.         movea.l    LREQBase(A5),A2        ;set requester base
  1566.         move.l    fr_NumArgs(A2),D2    ;read number of files
  1567.         subq.l    #1,D2            ;prepare filecounter
  1568.         move.l    D2,FileCnt(A5)        ;and save
  1569.  
  1570. ***********************************************  open asl requester (save) **
  1571.  
  1572.         moveq    #0,D0            ;want a filerequester
  1573.         lea    ASLTAG_S(pc),A0        ;set taglist
  1574.  
  1575.         moveq    #1,D1            ;set tag item (drawers only)
  1576.         lea    Title_S2(pc),A1        ;get tag item req_title2
  1577.  
  1578.         suba.l    A3,A3            ;clear initialfile
  1579.  
  1580.         tst.l    D2            ;test for multiple files
  1581.         bne.b    OpenLFile        ;branch if so
  1582.  
  1583.         moveq    #0,D1            ;unset tag item (drawers.. )
  1584.         lea    Title_S1(pc),A1        ;get tag item req_title1
  1585.  
  1586.         movea.l    fr_File(A2),A3        ;get initialfile
  1587.  
  1588. OpenLFile    move.l    D1,D3            ;save boolean (temp.)
  1589.  
  1590.         move.l    A3,20(A0)        ;set initialfile
  1591.  
  1592.         move.l    D1,12(A0)        ;set boolean value
  1593.         move.l    A1,04(A0)        ;set req_title
  1594.         jsr    _LVOAllocAslRequest(A6)    ;use ASL to (allocaslrequest)
  1595.         move.l    D0,SREQBase(A5)        ;save req_base
  1596.         beq    PrintFault0        ;branch on failure
  1597.  
  1598.         movea.l    D0,A0            ;set req_base
  1599.         suba.l    A1,A1            ;no more tags yet
  1600.         jsr    _LVOAslRequest(A6)    ;use ASL to open (aslrequest)
  1601.         tst.l    D0            ;test result
  1602.         beq    PrintFault0        ;branch on failure
  1603.  
  1604.         movea.l    SREQBase(A5),A2        ;set requester base
  1605.         movea.l    fr_File(A2),A2        ;get filename
  1606.         tst.b    (A2)            ;test for empty
  1607.         bne.b    QuitREQ            ;branch if not
  1608.         tst.l    D3            ;test boolean (drawers only)
  1609.         beq    ForceFault1        ;if unset, branch (arg mis.)
  1610.  
  1611. QuitREQ        st    ASLFlag(A5)        ;set flag (using ASL)
  1612.         rts                ;go back
  1613.  
  1614. *****************************************************************************
  1615.  
  1616. ASLTAG_L    dc.l    ASLFR_TitleText,0
  1617.         dc.l    ASLFR_DoMultiSelect,0
  1618.         dc.l    ASLFR_DoPatterns,1,0
  1619.  
  1620. ASLTAG_S    dc.l    ASLFR_TitleText,0
  1621.         dc.l    ASLFR_DrawersOnly,0
  1622.         dc.l    ASLFR_InitialFile,0
  1623.         dc.l    ASLFR_DoSaveMode,1,0
  1624.  
  1625. Title_L2    dc.b    "Select your files...",0
  1626. Title_S1    dc.b    "Save file as...",0
  1627. Title_S2    dc.b    "Select drawer to save...",0
  1628.  
  1629.         even
  1630.  
  1631. ***********************************************  check for wrong arguments **
  1632.  
  1633. CheckArgs    move.b    DRel32(A5),D0        ;get flag, want drel32?
  1634.         and.b    Reloc32(A5),D0        ;get flag, want reloc32?
  1635.         bne    ForceFault2        ;error, one flag only!
  1636.  
  1637.         move.b    DRel32(A5),D0        ;get flag, want drel32?
  1638.         bne.b    CheckFlags        ;branch if so
  1639.         move.b    Split(A5),D0        ;get flag, want split?
  1640.         bne    ForceFault2        ;error, requires drel32!
  1641.  
  1642. CheckFlags    or.b    Reloc32(A5),D0        ;one of these must be set
  1643.         or.b    Sort(A5),D0        ;one of these must be set
  1644.         or.b    Symbol(A5),D0        ;one of these must be set
  1645.         or.b    Debug(A5),D0        ;one of these must be set
  1646.         or.b    Name(A5),D0        ;one of these must be set
  1647.         or.b    Zeros(A5),D0        ;one of these must be set
  1648.         beq    ForceFault1        ;error if not
  1649.  
  1650. ************************************************ sort reverse (7.11.00) *****
  1651.  
  1652.         move.b    Reverse(A5),D0        ;get flag (sort reverse)
  1653.         beq.b    .Ready            ;branch if not set
  1654.         and.b    Sort(A5),D0        ;reverse requires sort
  1655.         beq    ForceFault1        ;branch if not set
  1656.  
  1657.         lea    SortDRel32(pc),A0    ;patch sortroutine (drel32)
  1658.         subq.b    #1,30(A0)        ;from bhi -> bls
  1659.         lea    SortReloc32(pc),A0    ;patch sortroutine (reloc32)
  1660.         subq.b    #1,30(A0)        ;from bhi -> bls
  1661.  
  1662.         movea.l    4.w,A6            ;set EXEC to call a function
  1663.         jsr    _LVOCacheClearU(A6)    ;use EXEC to clear cache
  1664.  
  1665. *****************************************************************************
  1666.  
  1667. .Ready        tst.l    LFile(A5)        ;test source list
  1668.         bne.b    CountFiles        ;branch if set
  1669.  
  1670.         tst.l    SFile(A5)        ;test destination
  1671.         bne    ForceFault1        ;branch if set (arg missing)
  1672.         rts                ;go back
  1673.  
  1674. ***********************************************
  1675.  
  1676. CountFiles    tst.l    AslReq(A5)        ;test flag
  1677.         bne    ForceFault2        ;branch if set (wrong number)
  1678.  
  1679.         movea.l    LFile(A5),A1        ;get filetable
  1680.         tst.l    (A1)+            ;skip first one
  1681.         moveq    #0,D0            ;initialize file counter
  1682.         tst.l    (A1)+            ;check for another entry
  1683.         beq.b    QuitChkArgs        ;branch if empty
  1684.  
  1685.         tst.l    SFile(A5)        ;is there a destination ?
  1686.         bne    ForceFault2        ;branch if so (wrong number)
  1687.  
  1688. CntFiles    addq    #1,D0            ;increment file counter
  1689.         tst.l    (A1)+            ;check next list-entry
  1690.         bne.b    CntFiles        ;until all files found
  1691.  
  1692. QuitChkArgs    addq    #4,SP            ;skip openreqs-routine
  1693.         pea    Main1(pc)        ;set new return address
  1694.  
  1695.         move.l    D0,FileCnt(A5)        ;save file count
  1696.  
  1697.         rts                ;go main1
  1698.  
  1699. ***********************************************  read arguments *************
  1700.  
  1701. ReadArgs    lea    Template(pc),A0        ;get argument template
  1702.         lea    ArgArray(A5),A1        ;get buffer (readarg array)
  1703.         move.l    A0,D1            ;set template
  1704.         move.l    A1,D2            ;set array
  1705.         moveq    #0,D3            ;no readarg structure
  1706.         movea.l    DOSBase(A5),A6        ;set DOS to call a function
  1707.         jsr    _LVOReadArgs(A6)    ;use DOS to (readarg)
  1708.         move.l    D0,RArgPtr(A5)        ;save pointer
  1709.         beq    PrintFault0        ;branch on fail
  1710.         rts                ;go back
  1711.  
  1712. ************************************************ sort reverse (7.11.00) *****
  1713.  
  1714. Template dc.b    "FILE/M,TO=AS,REPLACE/S,DREL32/S,SPLIT/S,RELOC32/S,SORT/S,"
  1715.      dc.b    "REVERSE/S,SYMBOL/S,DEBUG/S,NAME/S,ZEROS/S,ASLREQ/S,QUIET/S",0
  1716.      even
  1717.  
  1718. ***********************************************  prepare pr_result2 error ***
  1719.  
  1720. ForceFault4    move.w    #122,D1            ;preset ioerr (invalid lib.)
  1721.         bra.b    ForceFault0        ;branch (set ioerr)
  1722.  
  1723. ForceFault3    move.w    #304,D1            ;preset ioerr (break by user)
  1724.         bra.b    ForceFault0        ;branch (set ioerr)
  1725.  
  1726. ForceFault2    move.w    #118,D1            ;preset ioerr (to many args)
  1727.         bra.b    ForceFault0        ;branch (set ioerr)
  1728.  
  1729. ForceFault1    move.w    #116,D1            ;preset ioerr (args missing)
  1730.  
  1731. ForceFault0    ext.l    D1            ;clear upper word
  1732.         movea.l    DOSBase(A5),A6        ;set DOS to call a function
  1733.         jsr    _LVOSetIoErr(A6)    ;use DOS to (setioerr)
  1734.  
  1735. ***********************************************  print pr_result2 error *****
  1736.  
  1737. PrintFault0    movea.l    DOSBase(A5),A6        ;set DOS to call a function
  1738.         jsr    _LVOIoErr(A6)        ;use DOS to get (ioerr)
  1739.         move.l    D0,D1            ;set io_error
  1740.         beq.b    ForceFault1        ;branch when got nothing
  1741.  
  1742.         moveq    #0,D2            ;prepare register (no header)
  1743.         cmp.w    #304,D1            ;check for break by user
  1744.         beq.b    PrintFault1        ;branch if so
  1745.  
  1746.         lea    Header1(pc),A2        ;get header text
  1747.         move.l    A2,D2            ;want to print
  1748.  
  1749. PrintFault1    jsr    _LVOPrintFault(A6)    ;use DOS to (printfault)
  1750.  
  1751.         addq.l    #4,SP            ;clear old return address
  1752.         pea    Main4(pc)        ;set new return address
  1753.  
  1754.         moveq    #5,D0            ;set failat level (WARN)
  1755.         move.l    D0,RCode(A5)        ;set returncode
  1756.  
  1757.         rts                ;quit program
  1758.  
  1759. *****************************************************************************
  1760.  
  1761. Header1        dc.b    "StripHunk",0
  1762.  
  1763. *****************************************************************************
  1764.  
  1765.         if    BSS_Section
  1766.  
  1767.         SECTION    StripHunk_bss,BSS
  1768.  
  1769.         elseif
  1770.  
  1771.         cnop    0,4
  1772.  
  1773.         endc
  1774.  
  1775. *****************************************************************************
  1776.  
  1777. DataBase    ds.b    BSS_Size1
  1778.  
  1779.  end of file ****************************************************************
  1780.